home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / EXAMPLES / OBJVWS.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  3KB  |  192 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #else
  7. #include "vogl.h"
  8. #include "vodevice.h"
  9. #endif
  10.  
  11. #define        CUBE        1L
  12. #define        TOPLEFT        2L
  13. #define        TOPRIGHT    3L
  14. #define        BOTTOMLEFT    4L
  15. #define        BOTTOMRIGHT    5L
  16.  
  17. /*
  18.  * Demonstrate just how much you can put in an object
  19.  */
  20. main()
  21. {
  22.     void        makecube();
  23.  
  24.     Screencoord    minx, maxx, miny, maxy;
  25.     short        val;
  26.  
  27.     winopen("objvws");
  28.     unqdevice(INPUTCHANGE);
  29.     qdevice(KEYBD);
  30.  
  31.     getviewport(&minx, &maxx, &miny, &maxy);
  32.  
  33.  
  34.     pushviewport();
  35.  
  36.     hfont("futura.m");
  37.     htextsize(0.5, 0.9);
  38.  
  39.     color(BLACK);
  40.     clear();
  41.  
  42.     makecube();
  43.  
  44.     /*
  45.      * set up an object which draws in the top left of the screen.
  46.      */
  47.     makeobj(TOPLEFT);
  48.         viewport(minx, (maxx - minx) / 2, (maxy - miny) / 2, maxy);
  49.         ortho2(-5.0, 5.0, -5.0, 5.0);
  50.  
  51.         color(RED);
  52.  
  53.         rect(-5.0, -5.0, 5.0, 5.0);
  54.  
  55.         perspective(400, 1.0, 0.1, 1000.0);
  56.         lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0);
  57.  
  58.         callobj(CUBE);
  59.  
  60.         color(GREEN);
  61.  
  62.         move2(-4.5, -4.5);
  63.         hcharstr("perspective/lookat");
  64.     closeobj();
  65.  
  66.     /*
  67.      * now set up one which draws in the top right of the screen
  68.      */
  69.     makeobj(TOPRIGHT);
  70.         viewport((maxx - minx) / 2, maxx, (maxy - miny) / 2, maxy);
  71.         ortho2(-5.0, 5.0, -5.0, 5.0);
  72.  
  73.         color(GREEN);
  74.  
  75.         rect(-5.0, -5.0, 5.0, 5.0);
  76.  
  77.         window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  78.         lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0);
  79.  
  80.         callobj(CUBE);
  81.  
  82.         color(RED);
  83.  
  84.         move2(-4.5, -4.5);
  85.         hcharstr("window/lookat");
  86.     closeobj();
  87.  
  88.     /*
  89.      * try the bottom left
  90.      */
  91.     makeobj(BOTTOMLEFT);
  92.         viewport(minx, (maxx - minx) / 2, miny, (maxy - miny) / 2);
  93.         ortho2(-5.0, 5.0, -5.0, 5.0);
  94.  
  95.         color(MAGENTA);
  96.  
  97.         rect(-5.0, -5.0, 5.0, 5.0);
  98.  
  99.         perspective(400, 1.0, 0.1, 1000.0);
  100.         polarview(15.0, 300, 300, 300);
  101.  
  102.         callobj(CUBE);
  103.  
  104.         color(YELLOW);
  105.  
  106.         move2(-4.5, -4.5);
  107.         hcharstr("perspective/polarview");
  108.     closeobj();
  109.  
  110.     /*
  111.      * and the bottom right
  112.      */
  113.     makeobj(BOTTOMRIGHT);
  114.         viewport((maxx - minx) / 2, maxx, miny, (maxy - miny) / 2);
  115.         ortho2(-5.0, 5.0, -5.0, 5.0);
  116.  
  117.         color(CYAN);
  118.  
  119.         rect(-5.0, -5.0, 5.0, 5.0);
  120.  
  121.         window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  122.         polarview(8.0, -1800, -300, 1800);
  123.  
  124.         callobj(CUBE);
  125.  
  126.         color(BLUE);
  127.  
  128.         move2(-4.5, -4.5);
  129.         hcharstr("window/polarview");
  130.     closeobj();
  131.  
  132.     /*
  133.      * now draw them
  134.      */
  135.     callobj(TOPLEFT);
  136.     callobj(TOPRIGHT);
  137.     callobj(BOTTOMLEFT);
  138.     callobj(BOTTOMRIGHT);
  139.  
  140.     qread(&val);
  141.  
  142.     gexit();
  143. }
  144.  
  145. /*
  146.  * makecube
  147.  *
  148.  *    set up a cube
  149.  */
  150. void
  151. makecube()
  152. {
  153.     void    side();
  154.  
  155.     makeobj(CUBE);
  156.  
  157.         /*
  158.          * The border around the cube
  159.          */
  160.         rect(-5.0, -5.0, 10.0, 10.0);
  161.  
  162.         /*
  163.          * Make the cube from 4 squares
  164.          */
  165.         pushmatrix();
  166.             side();
  167.             rotate(900, 'x');
  168.             side();
  169.             rotate(900, 'x');
  170.             side();
  171.             rotate(900, 'x');
  172.             side();
  173.         popmatrix();
  174.  
  175.     closeobj();
  176. }
  177.  
  178. /*
  179.  * side
  180.  *
  181.  *    define a face for the cube
  182.  */
  183. void
  184. side()
  185. {
  186.     pushmatrix();
  187.         translate(0.0, 0.0, 1.0);
  188.         rect(-1.0, -1.0, 1.0, 1.0);
  189.     popmatrix();
  190. }
  191.  
  192.